package com.yanqu.road.server.manger.config.grandchild.skill.enums;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;

public enum eGrandChildSkillFlag {

    BIG(">", eGrandChildSkillFlag::f_big),

    SMALL("<", eGrandChildSkillFlag::f_small),

    EQ("=", eGrandChildSkillFlag::f_eq),

    NO_EQ("!=", eGrandChildSkillFlag::f_no_eq),

    NO_SMALL(">=", eGrandChildSkillFlag::f_no_small),

    NO_BIG("<=", eGrandChildSkillFlag::f_no_big),

    ;

    private static Map<String, eGrandChildSkillFlag> cacheMap = new ConcurrentHashMap<>();

    static {
        for (eGrandChildSkillFlag value : values()) {
            cacheMap.put(value.name, value);
        }
    }

    private String name;
    private BiFunction<Integer, Integer, Boolean> function;

    eGrandChildSkillFlag(String name, BiFunction<Integer, Integer, Boolean> function) {
        this.name = name;
        this.function = function;
    }

    public static eGrandChildSkillFlag getByName(String flagName) {
        return cacheMap.get(flagName);
    }

    public boolean getResult(int value1, int value2) {
        return function.apply(value1, value2);
    }

    // ========================  运算方法加在下面  ========================

    private static boolean f_big(int value1, int value2) {
        return value1 > value2;
    }

    private static boolean f_small(int value1, int value2) {
        return value1 < value2;
    }

    private static boolean f_eq(int value1, int value2) {
        return value1 == value2;
    }

    private static boolean f_no_eq(int value1, int value2) {
        return value1 != value2;
    }

    private static boolean f_no_small(int value1, int value2) {
        return value1 >= value2;
    }

    private static boolean f_no_big(int value1, int value2) {
        return value1 <= value2;
    }

}
